package com.basiclib.base

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import xc.common.framework.listener.NoShakeOnClickListener
import xc.common.framework.R

abstract class BaseFragment : Fragment(), NoShakeOnClickListener {


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(getLayoutId(), container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
        loadData()
    }

    fun startActivity(clazz: Class<out Activity>) {
        activity!!.startActivity(Intent(activity, clazz))
        activity!!.overridePendingTransition(
            R.anim.basiclib_slide_right_enter,
                R.anim.basiclib_slide_left_exit)
    }

    fun startActivity(clazz: Class<out Activity>, bundle: Bundle) {
        var intent = Intent(activity, clazz)
        intent.putExtras(bundle)
        activity!!.startActivity(intent)
        activity!!.overridePendingTransition(R.anim.basiclib_slide_right_enter,
                R.anim.basiclib_slide_left_exit)
    }

    abstract fun getLayoutId(): Int
    abstract fun initView()
    abstract fun loadData()
    abstract override fun onNoShakeClick(v: View)

    open fun onActivityRestart(){

    }
}